#coding=utf-8
"""
Author:杭州多测师_付佳美
Time:2025/5/6 19:07
website:https://duoceshi.net
"""

import yaml
from config.config import *
import os
class Read_Yaml():
    def __init__(self,file_path):
        self.file_path = file_path
        self.data = None
    def load_data_yaml(self):

        try:
            with open(self.file_path,'r',encoding="utf-8") as f:
                self.data = yaml.safe_load(f)
            print("Yaml 加载成功")
        except FileExistsError:
            print(f"错误：文件{self.file_path} 未找到")
        except yaml.YAMLError as e:
            print(f"错误：解析 YAML文件是错误-{e}")
        except Exception as e:
            print(f"未知错误：{e}")

    def get_data_yaml(self):

        if self.data is None:
            print("尚未加载YAML文件，请先调用load_data_yaml方法")
            return None
        return self.data

    def __str__(self):

        if self.data is None:
            return "尚未加载YAML文件"
        return str(self.data)
file = os.path.join(data_path,'data.yaml')
yaml_read = Read_Yaml(file)

yaml_read.load_data_yaml()

data = yaml_read.get_data_yaml()
print(data)
print(type(data),end=" ")
print(yaml_read)
















